home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / midi / midilb20.lha / examples / ht.c < prev    next >
C/C++ Source or Header  |  1988-10-23  |  2KB  |  77 lines

  1. /* simplified Hex Transmit to midi */
  2. /*
  3.     Shows usage of PutMidiStream() when buffer size is known and of managable
  4.     size.
  5. */
  6.  
  7.  
  8. #include <midi/midi.h>
  9. #include <functions.h>
  10.  
  11. void *MidiBase;
  12.  
  13. main (argc,argv)
  14. char **argv;
  15. {
  16.     struct MSource *source=0;
  17.     struct MRoute *route=0;
  18.     char buf[128];        /* buffer used for midi transfer */
  19.     long len;
  20.     extern int Enable_Abort;
  21.  
  22.     Enable_Abort = 0;        /* disable auto CTRL-C termination */
  23.  
  24.     if (argc < 2) {
  25.     printf ("MIDI Hex Transmit\n");
  26.     printf ("usage: ht <hex byte>...\n");
  27.     exit (1);
  28.     }
  29.  
  30.     if (!(MidiBase = OpenLibrary (MIDINAME,MIDIVERSION))) {
  31.     printf ("can't open midi.library\n");
  32.     goto clean;
  33.     }
  34.                 /* create our Source node (private) */
  35.     if (!(source = CreateMSource (NULL,NULL))) {
  36.     printf ("can't create Source\n");
  37.     goto clean;
  38.     }
  39.                 /* create out Route to MidiOut */
  40.     if (!(route = MRouteSource (source, "MidiOut", NULL))) {    /* use default RouteInfo in MidiOut */
  41.     printf ("can't create Route (can't find MidiOut?)\n");
  42.     goto clean;
  43.     }
  44.                 /* parse the command line for hex bytes, make into an array */
  45.     len = makestream (buf,argc-1,argv+1);
  46.                 /* convert array to midi messages and send */
  47.     PutMidiStream (source,NULL,buf,len,len);
  48.  
  49. clean:                /* clean up */
  50.     if (route) DeleteMRoute (route);
  51.     if (source) DeleteMSource (source);
  52.     if (MidiBase) CloseLibrary (MidiBase);
  53. }
  54.  
  55. makestream (buf,argc,argv)      /* convert args into an array of bytes, return length */
  56. char *buf;
  57. char **argv;
  58. {
  59.     int len=0;
  60.  
  61.     while (argc--) {
  62.     *buf++ = atox(*argv++);
  63.     len++;
  64.     }
  65.     return len;
  66. }
  67.  
  68.  
  69. atox(cp)                        /* like atoi() but read string as hex rather than decimal */
  70. char *cp;
  71. {
  72.     int x;
  73.  
  74.     sscanf (cp,"%x",&x);
  75.     return x;
  76. }
  77.